<template>
  <div class="home">
  <div v-loading="loading" element-loading-text="加载中..." style="min-height: 35vw;" v-if="!error">
    <div class="banner" >
      <div class="bg" ref="bg">
        <transition name="fade">
          <div style="position:absolute" @mouseover="stopTimer" @mouseout="startTimer">
            <img class="img1" v-if="mark == 0" src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4096806118,1276038326&fm=26&gp=0.jpg"/>
            <img class="img2 a" v-if="mark == 1" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01bd0057ce4b6a0000018c1b299441.jpg%401280w_1l_2o_100sh.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621790992&t=03f0cdd1a0df9391dfe6682415f80350"/>
            <img  class="img3 b" v-if="mark == 2" src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4096806118,1276038326&fm=26&gp=0.jpg"/>
          </div>
        </transition>
      </div>
      <div class="page">
        <ul class="dots">
          <li class="dot-active" v-for="(item, i) in 3" :class="{ 'dot':i!=mark }" :key="i" @click="change(i)"></li>
        </ul>
      </div>
    </div>

    <div>
      <div class="activity-panel">
        <!-- 首页分类列表typeList -->
        <ul class="box">
          <li class="content" v-for="(item,j) in typeList" :key="j" @click="linkTo(item, 1)">
            <img class="i" :src="item.url">
            <a class="cover-link"></a>
          </li>
        </ul>
      </div>
      <section class="w mt30 clearfix" >
        <y-shelf title="潮鞋合集">
          <div slot="content" class="floors" >
            <div class="imgbanner">
              <img src="./banner3.jpg">
              <a class="cover-link"></a>
            </div>
            <mall-goods :msg="item" v-for="(item,j) in shoes" :key="j+'key'"></mall-goods>
          </div>
        </y-shelf>
      </section>
      <section class="w mt30 clearfix">
        <y-shelf title="数码精选">
          <div slot="content" class="hot">
            <mall-goods :msg="item" v-for="(item,j) in digitProducts" :key="j"></mall-goods>
          </div>
        </y-shelf>
      </section>
      <section class="w mt30 clearfix">
        <y-shelf title="变美神器">
          <div slot="content" class="hot">
            <mall-goods :msg="item" v-for="(item,j) in beautyList" :key="j"></mall-goods>
          </div>
        </y-shelf>
      </section>
      <section class="w mt30 clearfix">
        <y-shelf title="包包配饰">
          <div slot="content" class="hot">
            <mall-goods :msg="item" v-for="(item,j) in bagList" :key="j"></mall-goods>
          </div>
        </y-shelf>
      </section>
    </div>
    </div>

    <div class="no-info" v-if="error">
      <div class="no-data">
        <img src="/static/images/error.png">
        <br> 抱歉！出错了...
      </div>
    </div>
  </div>
</template>
<script>
  import { getShoesList, getTypeList, getDigitProducts, getBeautyList, getBagList} from '/api/index.js'
  import YShelf from '/components/shelf'
  import product from '/components/product'
  import mallGoods from '/components/mallGoods'
  export default {
    data () {
      return {
        typeList: [],
        data: '',
        error: false,
        banner: [],
        mark: 0,
        bgOpt: {
          px: 0,
          py: 0,
          w: 0,
          h: 0
        },
        shoes: [],
        digitProducts: [],
        bagList: [],
        beautyList: [],
        loading: false,
        notify: '1',
        dialogVisible: false,
        timer: ''
      }
    },
    methods: {
      autoPlay() {
        this.mark++
        if (this.mark > this.banner.length - 1) {
          this.mark = 0
        }
      },
      play() {
        this.timer = setInterval(this.autoPlay, 2500)
      },
      startTimer() {
        this.timer = setInterval(this.autoPlay, 2500)
      },
      stopTimer() {
        clearInterval(this.timer)
      },
      change (i) {
        this.mark = i
      },
      linkTo (item, index) {
        if (index === 1) {
          // 按分类显示
          this.$router.push({
            path: '/goodsDetails',
            query: {
              productId: item.productId
            }
          })
        }
      }
    },
    created() {
         // 在售鞋子
        getShoesList().then(res => {
          this.shoes = res.data.list.filter(item => {
            return item.status == 1
          })
        })
        //  在售数码产品
        getDigitProducts().then(res => {
          this.digitProducts = res.data.list.filter(item => {
            return item.status == 1
          })
        })
        //  在售美妆产品
        getBeautyList().then(res => {
          this.beautyList = res.data.list.filter(item => {
            return item.status == 1
          })
        })
        //  在售包包配饰产品
        getBagList().then(res => {
          this.bagList = res.data.list.filter(item => {
            return item.status == 1
          })
        })
        // 分类列表图片
        getTypeList().then(res => {
          this.typeList = res.data.list
        })
    },
     mounted() {
      // this.loading = false
      this.play()
    },
    components: {
      YShelf,
      product,
      mallGoods
    }
  }
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
  .home {
    display: flex;
    flex-direction: column;
  }

  .no-info {
    padding: 100px 0;
    text-align: center;
    font-size: 30px;
    display: flex;
    flex-direction: column;
    .no-data{
      align-self: center;
    }
  }

  .fade-enter-active, .fade-leave-active {
    transition: opacity .5s;
  }
  .fade-enter, .fade-leave-to {
    opacity: 0;
  }

  .page { 
    position: absolute; 
    width: 100%;
    top: 470px;
    z-index: 30; 
    .dots {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      .dot-active { 
        display: inline-block; 
        width: 15px; 
        height: 15px; 
        background-color: whitesmoke; 
        border-radius: 8px; 
        margin-right: 10px; 
        cursor: pointer; 
      }
      .dot { 
        opacity: 0.2; 
      }
    }
  }

  .activity-panel {
    width: 1220px;
    margin: 0 auto;
    .box {
      overflow: hidden;
      position: relative;
      z-index: 0;
      margin-top: 25px;
      box-sizing: border-box;
      border: 1px solid rgba(0,0,0,.14);
      border-radius: 8px;
      background: #fff;
      box-shadow: 0 3px 8px -6px rgba(0,0,0,.1);
    }
    .content {
      float: left;
      position: relative;
      box-sizing: border-box;
      width: 25%;
      height: 200px;
      text-align: center;
    }
    .content ::before{
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
      box-sizing: border-box;
      border-left: 1px solid #f2f2f2;
      border-left: 1px solid rgba(0,0,0,.1);
      width: 100%;
      height: 100%;
      content: "";
      pointer-events: none;
    }
    .i {
      width: 305px;
      height: 200px;
    }
    .cover-link {
      cursor: pointer;
      display: block;
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      z-index: 4;
      background: url() repeat;
    }
    a {
      color: #5079d9;
      cursor: pointer;
      transition: all .15s ease-out;
      text-decoration: none;
    }
    a:hover {
      box-shadow: inset 0 0 38px rgba(0,0,0,.08);
      transition: all .15s ease;
    }
  }

  .banner, .banner span, .banner div {
    font-family: "Microsoft YaHei";
    transition: all .3s;
    transition-timing-function: linear;
  }

  .banner {
    cursor: pointer;
    perspective: 3000px;
    position: relative;
    z-index: 19;
    margin: 0 auto;
    width: 1220px;
  }

  .bg {
    position: relative;
    width: 1220px;
    height: 500px;
    margin: 20px auto;
    background-size: 100% 100%;
    border-radius: 10px;
    transform-style: preserve-3d;
    transform-origin: 50% 50%;
    transform: rotateY(0deg) rotateX(0deg);
    & div{
      position: relative;
      height: 100%;
      width: 100%;
    }
  }

  .img1 {
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    border-radius: 10px;
  }

  .img2 {
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    bottom: 5px;
    left: 0;
    background-size: 95% 100%;
    border-radius: 10px;
  }

  .img3 {
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    border-radius: 10px;
  }

  .a {
    z-index: 20;
    transform: translateZ(40px);
  }

  .b {
    z-index: 20;
    transform: translateZ(30px);
  }

  .c {
    transform: translateZ(0px);
  }

  .sk_item {
    width: 170px;
    height: 225px;
    padding: 0 14px 0 15px;
    > div {
      width: 100%;
    }
    a {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      transition: all .3s;
      &:hover {
        transform: translateY(-5px);
      }
    }
    img {
      width: 130px;
      height: 130px;
      margin: 17px 0;
    }
    .sk_item_name {
      color: #999;
      display: block;
      max-width: 100%;
      _width: 100%;
      overflow: hidden;
      font-size: 12px;
      text-align: left;
      height: 32px;
      line-height: 16px;
      word-wrap: break-word;
      word-break: break-all;
    }
    .sk_item_price {
      padding: 3px 0;
      height: 25px;
    }
    .price_new {
      font-size: 18px;
      font-weight: 700;
      margin-right: 8px;
      color: #f10214;
    }
    .price_origin {
      color: #999;
      font-size: 12px;
    }
  }

  .box {
    overflow: hidden;
    position: relative;
    z-index: 0;
    margin-top: 29px;
    box-sizing: border-box;
    border: 1px solid rgba(0, 0, 0, .14);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 3px 8px -6px rgba(0, 0, 0, .1);

  }

  ul.box {
    display: flex;
    li {
      flex: 1;
      img {
        display: block;
        width: 305px;
        height: 200px;
      }
    }
  }

  .mt30 {
    margin-top: 30px;
  }

  .hot {
    display: flex;
    > div {
      flex: 1;
      width: 25%;
    }
  }

  .floors {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    .imgbanner {
      width: 50%;
      height: 430px; 
      .cover-link {
        cursor: pointer;
        display: block;
        position: absolute;
        top: 60px;
        left: 0;
        width: 50%;
        height: 430px; 
        z-index: 4;
        background: url() repeat;
      }
      .cover-link:hover {
        box-shadow: inset 0 0 38px rgba(0,0,0,.08);
        transition: all .15s ease;
      }
    }
    img {
      display: block;
      width: 100%;
      height: 100%;
    }
  }

</style>
